package net.jeeshop.web.action.front.bbs;

import net.jeeshop.core.Services;
import net.jeeshop.services.front.account.bean.Account;
import net.jeeshop.services.front.bbs.BbsCommentService;
import net.jeeshop.services.front.bbs.BbsDetailService;
import net.jeeshop.services.front.bbs.BbsImgService;
import net.jeeshop.services.front.bbs.bean.BbsDetail;
import net.jeeshop.services.front.bbs.bean.BbsImg;
import net.jeeshop.web.action.front.FrontBaseController;
import net.jeeshop.web.util.LoginUserHolder;
import org.apache.commons.lang.StringUtils;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by zuohao on 16/7/7.
 */
@Controller("frontBbsImgAction")
@RequestMapping("bbsImg")
public class BbsImgAction extends FrontBaseController<BbsImg> {

    private static final org.slf4j.Logger logger = LoggerFactory.getLogger(BbsImgAction.class);


    @Autowired
    private BbsImgService bbsImgService;

    @Override
    public Services<BbsImg> getService() {
        return bbsImgService;
    }

    @RequestMapping("selectBbsImgByBbsDetailId")
    @ResponseBody
    public Map<String,Object> selectBbsImgByBbsDetailId(@RequestParam("detailId")String detailId){
        Map<String,Object> map=new HashMap<String, Object>();
        map.put("detailId",detailId);
        Map<String,Object> result=new HashMap<String, Object>();
        result.put("bbsImgList",bbsImgService.selectBbsImgByBbsDetailId(map));
        return result;
    }

//    @RequestMapping("insertBbsDetail")
//    @ResponseBody
//    public String insertBbsDetail(@RequestParam("content")String content,
//                                   @RequestParam("categoryCode")String categoryCode){
//        ShopRule acc = LoginUserHolder.getLoginAccount();
//        Map<String,Object> result=new HashMap<String, Object>();
//        if (acc == null || StringUtils.isBlank(acc.getAccount())) {
//            return "请先登录";
//        }
//        BbsDetail bbsDetail=new BbsDetail();
//        bbsDetail.setContent(content);
//        bbsDetail.setCategoryCode(categoryCode);
//        bbsDetail.setCreateId(acc.getId());
//        bbsDetail.setStatus("y");
//        bbsDetail.setCreateTime(sdf.format(System.currentTimeMillis()));
//        bbsDetailService.insertBbsDetail(bbsDetail);
//        return "true";
//    }

//    @RequestMapping("deleteBbsDetailById")
//    @ResponseBody
//    public String deleteBbsDetailById(@RequestParam("detailId")String detailId) {
//        ShopRule acc = LoginUserHolder.getLoginAccount();
//        Map<String,Object> result=new HashMap<String, Object>();
//        if (acc == null || StringUtils.isBlank(acc.getAccount())) {
//            return "请先登录";
//        }
//        //用户只能操作当前用户的数据
//        String createId=acc.getId();
//        Map<String,Object> map=new HashMap<String, Object>();
//        map.put("createId",createId);
//        map.put("detailId",detailId);
//        bbsDetailService.deleteBbsDetailById(map);
//        bbsCommentService.deleteBbsCommentByDetailId(detailId);
//        return "true";
//    }

}
